package k_singleton.a_design_pattern.a_thread_unsafe_lazy;

/**
 * Created by wug on 2016/7/15 0015.
 * 懒汉式，线程不安全
 * 解决的问题：使得一个类只能够创建一个对象
 */
public class Singleton {
    private static Singleton instance;
    private Singleton (){}

    public static Singleton getInstance() {
        if (instance == null) {
            /**
             * 为了展现出错误,我们加了等待时间,以延长初始化的时间
             */
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            instance = new Singleton();
        }
        return instance;
    }
}
